package org.aspectsense.middleware.monitor;

import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;

/**
 * Implements the OSGi bundle listener for listening to bundle changes.<p>
 * Whenever a new <code>BundleEvent</code> is generated it overrides the
 * bundleChanged method to catch and manage received bundle event.
 */
public class DefaultBundleListener implements BundleListener
{

	    @Override
	    /**
	     * Overrides the OSGi <code>bundleChanged</code> method
	     * in order to catch bundle events
	     */
	    public void bundleChanged (BundleEvent event)
	    {
	        System.out.println("DefaultBundleListener::bundleChanged -> " +
	                event + " / "
	                + getTypeAsString(event.getType()));
	    }

	    private String getTypeAsString(final int code)
	    {
	        switch (code)
	        {
	            case BundleEvent.INSTALLED: return "installed";
	            case BundleEvent.STARTED: return "started";
	            case BundleEvent.STOPPED: return "stopped";
	            case BundleEvent.UPDATED: return "updated";
	            case BundleEvent.UNINSTALLED: return "uninstalled";
	            case BundleEvent.RESOLVED: return "resolved";
	            case BundleEvent.UNRESOLVED: return "unresolved";
	            case BundleEvent.STARTING: return "starting";
	            case BundleEvent.STOPPING: return "stopping";
	            case BundleEvent.LAZY_ACTIVATION: return "lazy_activation";
	            default: return "*unknown*";
	        }
	    }


}
	
